<?php
namespace app\admin\controller;
use think\Config;
use think\Session;
use think\Db;

class Classify extends Base
{
    /**
     * 数据展示
     * @return html
     */
    public function index(){
        $title=input('title');
        $where=array();
        if ($title){
            $where['name']=['like','%'.$title.'%'];
        }
        $list = db("eb_grade")->where($where)->paginate( 5);
        $data  = $list->items();
        $this->assign('data',$data);
        $this->assign('list',$list);
        return $this->fetch();
    }

    /**
     * 添加分类
     * @return html
     */
    public function add()
    {
        $data = db('eb_grade')->select();
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function toadd()
    {
        $data        = input();
        $Classify = model( 'Classify' );
		$list = $Classify->creat( $data );
        if( $list) {
            $this->success( '添加成功' , url( 'Classify/index' ) );
        } else {
            $this->error( '添加失败' );
        }
    }

    /**
     * 修改分类
     * @return html
     */

    public function edit($id)
    {
        $find  = db( 'eb_grade' )->where( ['id'=>$id] )->find();
        $this->assign( 'find', $find );
        return $this->fetch();
    }
    public function update($id){
        $data        = input();
        $Classify = model( 'Classify' );
        $list = $Classify->edit( $id,$data );
        if( $list) {
            $this->success( '编辑成功' , url( 'Classify/index' ) );
        } else {
            $this->error( '编辑失败' );
        }
    }
    /**
     * 删除分类
     * @return html
     */
    public function remove($id)
    {
        $Classify = model( 'Classify' );
        $list = $Classify->del( $id );
        if ($list) {
            $this->success('删除成功' , url("Classify/index"));
        } else {
            $this->error('删除失败');
        }
    }

    /**
     * 搜索分类
     * @return html
     */

    public function stair(){
        if (request()->Post()){
            $data=input('title');
            $where=array();
            if ($data){
                 $where['name']=['like','%'.$data.'%'];
            }
        }
    }
}

?>